/**
 * Title: PhoneNumberUncaughtExceptionHandler.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-8-5 上午11:57:46
 * Version 1.0 
 */
package com.luoxudong.phonenumber.service.exception; 	

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler;

import android.content.Context;
import android.os.Process;

import com.luoxudong.phonenumber.service.utils.MetaDataUtil;

/** 
 * ClassName: PhoneNumberUncaughtExceptionHandler 
 * Description:TODO(这里用一句话描述这个类的作用) 
 * Create by 罗旭东
 * Date 2013-8-5 上午11:57:46 
 */
public abstract class PhoneNumberUncaughtExceptionHandler implements UncaughtExceptionHandler{
	private UncaughtExceptionHandler uncaughtExceptionHandler = null;
	private Context context = null;
	
	public PhoneNumberUncaughtExceptionHandler(Context context)
	{
		this.uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
		this.context = context;
	}
	
	@Override
	public void uncaughtException(Thread t, Throwable e) {
		ByteArrayOutputStream errorOs = new ByteArrayOutputStream();
		
		e.printStackTrace(new PrintStream(errorOs));
		report(context, "testUser", errorOs.toString());
		
		if (MetaDataUtil.isShowUncaughtexception(context))
		{
			uncaughtExceptionHandler.uncaughtException(t, e);
		}
		else
		{
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			Process.killProcess(Process.myPid());
		}
	}
	
	public abstract void report(Context context, String userName, String msg);

}
